using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Collections;

using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Net.Sockets;

namespace Mud.EmlenMudMain
{
#if NO_SILVERLIGHT
    [Serializable]
#endif
    public class DynamicRoomDetails : EmlenMudMain.IDynamicRoomDetails
    {
        #region "Private Data"
        private int copper = 0;			/* CopperCoins in currentRoom */
        private int gold = 0;			/* GoldCoins in currentRoom */

#if NO_SILVERLIGHT
        [NonSerialized]
#endif
        public Dictionary<string, ITrackData> trcks = new Dictionary<string, ITrackData>(8);		/* Tracks in this currentRoom */
#if NO_SILVERLIGHT
        [NonSerialized]
#endif
        public int plrsInRoom = 0;			/* Player CharactersInRoom in currentRoom */
#if NO_SILVERLIGHT
        [NonSerialized]
#endif
        public List<CharacterData> chrsInRoom = new List<CharacterData>(2);		/* Character list in currentRoom */
#if NO_SILVERLIGHT
        [NonSerialized]
#endif
        public int lght = 0;		/* LightingAmount value of the currentRoom */
#if NO_SILVERLIGHT
        [NonSerialized]
#endif
        private List<ObjectData> contents = new List<ObjectData>(2);	/* Object contents of currentRoom */
        #endregion

        #region "Properties"
        public int CopperCoins
        {
            get { return copper; }
            set { copper = value; }
        }

        public int GoldCoins
        {
            get { return gold; }
            set { gold = value; }
        }

        public Dictionary<string, ITrackData> Tracks
        {
            get { return trcks; }
            set { trcks = value; }
        }

        public List<ObjectData> ObjectsInRoom
        {
            get
            {
                if (contents == null) contents = new List<ObjectData>(2);
                return contents;
            }
            set { contents = value; }
        }

        public int NumberOfPlayersInRoom
        {
            get { return plrsInRoom; }
            set { plrsInRoom = value; }
        }

        public List<CharacterData> CharactersInRoom { get { return chrsInRoom; } set { chrsInRoom = value; } }

        public int LightingAmount
        {
            get { return lght; }
            set { lght = value; }
        }
        #endregion
    }


    // OLD CODE to PORT: climbable support
    /* climb any item of type ITEM_CLIMBABLE 
     Some of this code was borrowed from the previous mud code 
  */
    //void 
    //do_climb (CharacterData  chr, string szUserArguments)
    //{
    //  CharacterData fch, *fch_next;
    //  SINGLE_OBJECT *obj;
    //  ROOM_DATA *to_room;
    //  ROOM_DATA *inRoom;
    //  I_CLIMBABLE *c;
    //  string arg;
    //  char buf[SML_LENGTH];
    //  char arg1[SML_LENGTH];
    //  char arg2[SML_LENGTH];
    //  int moveDirection;
    //  DEFINE_COMMAND ("climb", do_climb, POSITION_STANDING, 0, NORMAL, "Allows you to climb up <object> or climb down <object>.")


    //    arg = one_argy (szUserArguments, arg2);
    //  one_argy (arg, arg1);
    //  if (arg1[0] == '\0')
    //    {
    //      send_to_char ("Climb what?\n\r", chr);
    //      return;
    //    }
    //  if ((obj = get_obj_here (chr, arg1, SEARCH_ROOM_FIRST)) == NULL)
    //    {
    //      send_to_char ("There's nothing here to climb.\n\r", chr);
    //      return;
    //    }
    //  if (obj->pIndexData->item_type == ITEM_SCALABLE)
    //    {
    //      if (get_item_held (chr, ITEM_SCALE_DEV) == NULL)
    //   {
    //     send_to_char ("You need something to scale it with.\n\r", chr);
    //     return;
    //   }
    //    }
    //  else if (obj->pIndexData->item_type != ITEM_CLIMBABLE)
    //    {
    //      send_to_char ("You can't climb that!\n\r", chr);
    //      return;
    //    }
    //  c = (I_CLIMBABLE *) obj->MoreRoomInfo;
    //  if (RIDING (chr) != NULL)
    //    {
    //      send_to_char ("You're mounted; you can't climb!\n\r", chr);
    //      return;
    //    }
    //  if (MOUNTED_BY (chr) != NULL)
    //    {
    //      send_to_char ("You can't climb while mounted.\n\r", chr);
    //      return;
    //    }
    //  moveDirection = c->up_down;
    //  if (arg2[0] == '\0' && moveDirection == 2)
    //    {
    //      send_to_char ("Which way? Up or down?\n\r", chr);
    //      return;
    //    }
    //  inRoom = chr->inRoom;
    //  switch (arg2[0])
    //    {
    //    case 'U':
    //    case 'u':
    //      if (moveDirection == 0)
    //   {
    //     send_to_char ("It doesn't lead anywhere.\n\r", chr);
    //     return;
    //   }
    //      else
    //   {
    //     if ((to_room = get_room_index (c->above)) == NULL)
    //       {
    //         send_to_char ("It doesn't lead anywhere.\n\r", chr);
    //         bug ("Do_climb: bad vnumClan up %d.",
    //         c->above);
    //         return;
    //       }
    //     moveDirection = 1;
    //   }
    //      break;
    //    case 'D':
    //    case 'd':
    //      if (moveDirection == 1)
    //   {
    //     send_to_char ("It doesn't lead anywhere.\n\r", chr);
    //     return;
    //   }
    //      else
    //   {
    //     if ((to_room = get_room_index (c->below)) == NULL)
    //       {
    //         send_to_char ("It doesn't lead anywhere.\n\r", chr);
    //         bug ("Do_climb: bad vnumClan down %d.",
    //         c->below);
    //         return;
    //       }
    //     moveDirection = 0;
    //   }
    //      break;
    //    default:
    //      if (moveDirection == 0)
    //   {
    //     if ((to_room = get_room_index (c->below)) == NULL)
    //       {
    //         send_to_char ("It doesn't lead anywhere.\n\r", chr);
    //         bug ("Do_climb: bad vnumClan down %d.",
    //         c->below);
    //         return;
    //       }
    //   }
    //      else
    //   {
    //     if ((to_room = get_room_index (c->above)) == NULL)
    //       {
    //         send_to_char ("It doesn't lead anywhere.\n\r", chr);
    //         bug ("Do_climb: bad vnumClan up %d.",
    //         c->above);
    //         return;
    //       }
    //     moveDirection = 1;
    //   }
    //      break;
    //    }
    //  if (IS_PLAYER (chr))
    //    {
    //      int MPCurrent = 0;
    //      MPCurrent -= chr->pcdata->carry_number - get_curr_str (chr);
    //      if (MPCurrent < 2)
    //   MPCurrent = 2;
    //      if (chr->MPCurrent < MPCurrent)
    //   {
    //     send_to_char ("You are too exhausted.\n\r", chr);
    //     return;
    //   }
    //      WAIT_STATE (chr, 1);
    //      SUBMOVE(chr,MPCurrent);
    //    }
    //  if (MOUNTED_BY (chr) != NULL)
    //    sprintf (buf, "You climb %s %s, rode by %s.",
    //        (moveDirection == 0 ? "down" : "up"), obj->pIndexData->short_descr,
    //        PERS (MOUNTED_BY (chr), chr));
    //  else if (IS_AFFECTED (chr, AFF_SNEAK))
    //    sprintf (buf, "You sneak %s %s.",
    //        (moveDirection == 0 ? "down" : "up"), obj->pIndexData->short_descr);
    //  else if (IS_AFFECTED (chr, AFF_FLYING))
    //    sprintf (buf, "You fly %s %s.",
    //        (moveDirection == 0 ? "down" : "up"), obj->pIndexData->short_descr);
    //  else
    //    sprintf (buf, "You climb %s %s.",
    //        (moveDirection == 0 ? "down" : "up"), obj->pIndexData->short_descr);
    //  buf[0] = UPPER (buf[0]);
    //  send_to_char (buf, chr);
    //  send_to_char ("\n\r", chr);
    //  check_room_more (inRoom);
    //  for (fch = inRoom->MoreRoomInfo->people; fch != NULL; fch = fch_next)
    //    {
    //      fch_next = fch->next_in_room;
    //      if (chr == fch || MOUNTED_BY (chr) == fch)
    //   continue;
    //      if (!can_see (fch, chr))
    //   continue;
    //      if (MOUNTED_BY (chr) != NULL)
    //   break;
    //      else if (IS_AFFECTED (chr, AFF_SNEAK))
    //   {
    //     if (IS_SET (fch->currentActionsAndBehavior, PLR_HOLYLIGHT))
    //       sprintf (buf, "%s sneaks %s %s.", PERS (chr, fch),
    //           (moveDirection == 0 ? "down" : "up"),
    //           obj->pIndexData->short_descr);
    //     else
    //       buf[0] = '\0';
    //   }
    //      else if (IS_MOB (chr) && IS_SET (chr->currentActionsAndBehavior, ACT_SCRAMBLE))
    //   sprintf (buf, "%s rushes %s %s.", PERS (chr, fch),
    //       (moveDirection == 0 ? "down" : "up"),
    //       obj->pIndexData->short_descr);
    //      else if (IS_AFFECTED (chr, AFF_FLYING))
    //   sprintf (buf, "%s flies %s %s.", PERS (chr, fch),
    //       (moveDirection == 0 ? "down" : "up"),
    //       obj->pIndexData->short_descr);
    //      else
    //   sprintf (buf, "%s climbs %s %s.", PERS (chr, fch),
    //       (moveDirection == 0 ? "down" : "up"),
    //       obj->pIndexData->short_descr);
    //      buf[0] = UPPER (buf[0]);
    //      send_to_char (buf, fch);
    //      if (buf[0] != '\0')
    //   send_to_char ("\n\r", fch);
    //    }
    //  char_from_room (chr);
    //  char_to_room (chr, to_room);
    //  if (MOUNTED_BY (chr) != NULL && chr->inRoom != MOUNTED_BY (chr)->inRoom)
    //    {
    //      do_climb (MOUNTED_BY (chr), szUserArguments);
    //    }
    //  check_room_more (inRoom);
    //  for (fch = to_room->MoreRoomInfo->people; fch != NULL; fch = fch_next)
    //    {
    //      fch_next = fch->next_in_room;
    //      if (chr == fch || MOUNTED_BY (chr) == fch)
    //   continue;
    //      if (!can_see (fch, chr))
    //   continue;
    //      if (MOUNTED_BY (chr) != NULL)
    //   break;
    //      else if (IS_AFFECTED (chr, AFF_SNEAK))
    //   {
    //     if (IS_SET (fch->currentActionsAndBehavior, PLR_HOLYLIGHT))
    //       sprintf (buf, "%s sneakily climbs %s from %s.", PERS (chr, fch),
    //           (moveDirection == 0 ? "down" : "up"),
    //           (moveDirection == 0 ? "above" : "below"));
    //     else
    //       buf[0] = '\0';
    //   }
    //      else if (IS_MOB (chr) && IS_SET (chr->currentActionsAndBehavior, ACT_SCRAMBLE))
    //   sprintf (buf, "%s rushes %s from %s.", PERS (chr, fch),
    //       (moveDirection == 0 ? "down" : "up"),
    //       (moveDirection == 0 ? "above" : "below"));
    //      else if (IS_AFFECTED (chr, AFF_FLYING))
    //   sprintf (buf, "%s flies %s from %s.", PERS (chr, fch),
    //       (moveDirection == 0 ? "down" : "up"),
    //       (moveDirection == 0 ? "above" : "below"));
    //      else
    //   sprintf (buf, "%s climbs %s from %s.", PERS (chr, fch),
    //       (moveDirection == 0 ? "down" : "up"),
    //       (moveDirection == 0 ? "above" : "below"));
    //      buf[0] = UPPER (buf[0]);
    //      if (IS_AWAKE (fch))
    //   send_to_char (buf, fch);
    //      if (buf[0] != '\0')
    //   send_to_char ("\n\r", fch);
    //    }
    //  do_look (chr, "auto");
    //  if (HUNTING (chr) != NULL)
    //    do_track (chr, "continue");
    //  check_room_more (inRoom);
    //  for (fch = inRoom->MoreRoomInfo->people; fch != NULL; fch = fch_next)
    //    {
    //      fch_next = fch->next_in_room;
    //      if (MASTER (fch) == chr && fch->position >= POSITION_STANDING)
    //   {
    //     currentActionsAndBehavior ("You follow $N $t.", fch,
    //          (moveDirection == 0 ? "down" : "up"), chr, TO_CHAR);
    //     do_climb (fch, szUserArguments);
    //   }
    //    }
    //  if (IS_PLAYER (chr) && IS_SET (chr->pcdata->act3, ACT3_MAPPING) &&
    //      !IS_SET (chr->pcdata->act3, ACT3_DISABLED))
    //    {
    //      REMOVE_BIT (chr->pcdata->act3, ACT3_MAPPING);
    //      do_drawmort (chr, "");
    //    }
    //  return;
    //}

    // OLD CODE to PORT: currentRoom deletion
    //   void 
    //mark_delete (CharacterData  chr, string szUserArguments)
    //{
    //  DEFINE_COMMAND ("roomdelete", mark_delete, POSITION_DEAD, 110, ALWAYS, "This command marks a currentRoom for deletion (so that the currentRoom will NOT be saved from then on).")
    //    if (chr->inRoom->MoreRoomInfo && chr->inRoom->MoreRoomInfo->NumberOfPlayersInRoom == 31999)
    //    {
    //      send_to_char ("Delete mark removed.. currentRoom will now save.\n\r", chr);
    //      chr->inRoom->MoreRoomInfo->NumberOfPlayersInRoom = 1;
    //    }
    //  else
    //    {
    //      if (chr->inRoom->MoreRoomInfo)
    //   chr->inRoom->MoreRoomInfo->NumberOfPlayersInRoom = 31999;
    //      send_to_char ("Room marked NOT to save.\n\r", chr);
    //    }

    //  return;
    //}

    // OLD CODE to PORT:

    //void
    //clean_blank_rooms (CharacterData  chr, string szUserArguments)
    //{
    //   ROOM_DATA *oneroom;
    //   EXIT_DATA *pexit;
    //   int iHash;
    //   int door;
    //   bool allf = FALSE;
    //   DEFINE_COMMAND ("cleanblankrooms", clean_blank_rooms, POSITION_DEAD, 110, ALWAYS, "For Orin's use only.")
    //      if (!str_cmp (szUserArguments, "all"))
    //         allf = TRUE;

    //   for (iHash = 0; iHash < HASH_MAX; iHash++)
    //   {
    //      for (oneroom = room_hash[iHash];
    //         oneroom != NULL;
    //         oneroom = oneroom->next)
    //      {
    //         bool fexit;
    //         if (!allf && oneroom->area != chr->inRoom->area)
    //            continue;
    //         if (oneroom->vnumClan < 1202 || oneroom->area->open == 0)
    //            continue;
    //         fexit = FALSE;
    //         for (door = 0; door <= 5; door++)	/*Does currentRoom have an exit? */
    //         {
    //            if (
    //               ((pexit = oneroom->exit[door]) != NULL) &&
    //               pexit->to_room != NULL)
    //            {
    //               fexit = TRUE;
    //               break;
    //            }
    //         }

    //         if (!fexit && (!oneroom->MoreRoomInfo || oneroom->MoreRoomInfo->reset_first == NULL) && (!pexit))
    //         {			/*Room doesn't have an exit, and no resets! */
    //            char tmpbuf[STD_LENGTH];
    //            sprintf (tmpbuf, "Room %d marked for deletion!\n\r", oneroom->vnumClan);
    //            dd.SendTelnetCommand (chr->description, tmpbuf, 0);
    //            check_room_more (oneroom);
    //            oneroom->MoreRoomInfo->NumberOfPlayersInRoom = 31999;
    //         }
    //      }
    //   }

    //   return;
    //}
}
